package com.qingxin.sys.mvc;

import com.qingxin.sys.utils.StringUtils;

public class PageParam {

	private Integer page;
	private Integer pagesize;
	private String sortname;
	private String sortorder;
	
	
	public PageParam() {
	}
	
	
	public Integer getPage() {
		if(page == null || page < 1){
			setPage(1);
		}
		return page;
	}
	public void setPage(Integer page) {
		this.page = page;
	}
	public Integer getPagesize() {
		if(pagesize == null || pagesize < 1){
			setPagesize(20);
		}
		return pagesize;
	}
	public void setPagesize(Integer pagesize) {
		this.pagesize = pagesize;
	}
	public String getSortname() {
		return sortname;
	}
	public void setSortname(String sortname) {
		this.sortname = sortname;
	}
	public String getSortorder() {
		return sortorder;
	}
	public void setSortorder(String sortorder) {
		this.sortorder = sortorder;
	}
	
	
	
	public String getOrderby(String orderby){
		if(StringUtils.isNotEmpty(sortname) && StringUtils.isNotEmpty(sortorder)){
			return " order by "+sortname+" "+sortorder;
		}
		return orderby;
	}
	
	public String getOrderby(String orderby, String alias){
		if(StringUtils.isNotEmpty(sortname) && StringUtils.isNotEmpty(sortorder)){
			if(StringUtils.isNotEmpty(alias)){
				return " order by "+alias+"."+sortname+" "+sortorder;
			}
			return " order by "+sortname+" "+sortorder;
		}
		return orderby;
	}
	
	
}
